package org.correct.correcter;

import java.io.StringReader;
import java.util.ArrayList;


import org.wltea.analyzer.*; 
public class IKAnalysis {

	/*
	public static void main(String args[])
	{
		ArrayList result = getWords("��ִ����캯��Ĭ��ʵ����ϸc���з�,��ȡ�ִ����зֳ��word��һ������spring��Ԫ������null����ʾ�ִ����Ѿ����� ����");
		for(int i = 0; i < result.size(); i++)
		{
			System.out.println(result.get(i));
		}
	}
	*/
	public static ArrayList<String> getWords(String searchList)
	{
		ArrayList<String> result = new ArrayList<String>();
		StringReader input = new StringReader(searchList);
		
		IKSegmentation aTest = new IKSegmentation(input,true);
		
		try
		{
			Lexeme a = aTest.next();
			while(a != null)
			{
				
				result.add(a.getLexemeText());
				//System.out.println("fenci jieguo: "+a.getLexemeText());
				a = aTest.next();
				
			}
		}
		catch (Exception e)
		{
			System.out.println(e);
		}
		ArrayList<String> Fresult = new ArrayList<String>();
		int j = 0;
		for(int i = 0; i < result.size(); i++)
		{
			if(i < result.size() -1)
			{
				if((result.get(i).length() == 1)&&(result.get(i+1).length() == 1))
				{
					String temp = result.get(i)+result.get(i+1);
					if( j > 0)
					{
						String pre = Fresult.get(j-1);
						if(!pre.contains(temp))
						{
							Fresult.add(temp);
							j++;
						}
					}
					else
					{
						Fresult.add(temp);
						j++;
					}
					
				}
				else
				{
					if( j > 0)
					{
						String pre = Fresult.get(j-1);
						if(!pre.contains(result.get(i)))
						{
							Fresult.add(result.get(i));
							j++;
						}
					}
					else
					{
						Fresult.add(result.get(i));
						j++;
					}
				}
			}
			else
			{
				if( j > 0)
				{
					String pre = Fresult.get(j-1);
					if(!pre.contains(result.get(i)))
					{
						Fresult.add(result.get(i));
						j++;
					}
				}
				else
				{
					Fresult.add(result.get(i));
					j++;
				}
			}
		}
		return Fresult;
	}
}
